import 'package:backend.purchases/infrastructure/dtos/yookassa_api/payments/canceled_payment/yookassa_api_canceled_payment_dto.dart';
import 'package:backend.purchases/infrastructure/dtos/yookassa_api/payments/pending_payment/yookassa_api_pending_payment_dto.dart';
import 'package:backend.purchases/infrastructure/dtos/yookassa_api/payments/succeeded_payment/yookassa_api_succeeded_payment_dto.dart';
import 'package:backend.purchases/infrastructure/dtos/yookassa_api/payments/yookassa_api_payment_dto.dart';

class YookassaApiPaymentDtoFactory {
  const YookassaApiPaymentDtoFactory._internal();

  static const _instance = YookassaApiPaymentDtoFactory._internal();

  factory YookassaApiPaymentDtoFactory() {
    return _instance;
  }

  YookassaApiPaymentDto fromJson(Map<String, dynamic> json) {
    final type = json[kYookassaApiPaymentTypeKey] as String;

    if (type == kYookassaApiPendingPaymentTypeValue) {
      return YookassaApiPendingPaymentDto.fromJson(json);
    }

    if (type == kYookassaApiSucceededPaymentTypeValue) {
      return YookassaApiSucceededPaymentDto.fromJson(json);
    }

    if (type == kYookassaApiCanceledPaymentTypeValue) {
      return YookassaApiCanceledPaymentDto.fromJson(json);
    }

    throw UnimplementedError();
  }
}
